
package handling.channel.handler;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import server.maps.AnimatedMapleMapObject;
import server.movement.*;
import tools.data.input.LittleEndianAccessor;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;
















 public class MovementParse {
    /*  19 */   public static final Logger log = LogManager.getLogger(MovementParse.class.getName());












    public static List<LifeMovementFragment> parseMovement(LittleEndianAccessor lea, int kind) {
        /*  31 */
        List<LifeMovementFragment> res = new ArrayList<>();
        /*  32 */
        byte numCommands = lea.readByte();
        /*  33 */
        String packet = lea.toString(true);
        byte i;
        /*  34 */
        for (i = 0; i < numCommands; i = (byte) (i + 1)) {
            /*  35 */
            short s2, xmod, s1;
            byte newstate;
            short xpos, s4, ymod, s3, duration, ypos, unk, s5;
            byte b1;
            short fh;
            byte end;
            short xwobble, s8, s7, s6;
            byte b2;
            AranMovement am;
            short ywobble;
            byte b5;
            short s11;
            byte b4;
            short s10, s9;
            byte b3;
            short s13, sub;
            RelativeLifeMovement rlm;
            byte b7, b6;
            short s12;
            BounceMovement bm;
            short xoffset;
            ChairMovement cm;
            short s14;
            UnknownMovement um;
            short yoffset;
            byte b8;
            short unk161p;
            StaticLifeMovement slm;
            byte b9;
            short s15;
            byte b10;
            AbsoluteLifeMovement alm;
            byte command = lea.readByte();
            /*  36 */
            switch (command) {

                case -1:
                    /*  38 */
                    s2 = lea.readShort();
                    /*  39 */
                    s4 = lea.readShort();
                    /*  40 */
                    unk = lea.readShort();
                    /*  41 */
                    s8 = lea.readShort();
                    /*  42 */
                    b5 = lea.readByte();
                    /*  43 */
                    s13 = lea.readShort();
                    /*  44 */
                    bm = new BounceMovement(command, new Point(s2, s4), s13, b5);
                    /*  45 */
                    bm.setFH(s8);
                    /*  46 */
                    bm.setUnk(unk);
                    /*  47 */
                    res.add(bm);

                    break;


                case 0:

                case 8:

                case 15:

                case 17:

                case 19:

                case 69:

                case 70:

                case 71:

                case 72:

                case 73:

                case 74:

                case 92:
                    /*  62 */
                    s2 = lea.readShort();
                    /*  63 */
                    s4 = lea.readShort();
                    /*  64 */
                    s5 = lea.readShort();
                    /*  65 */
                    s7 = lea.readShort();
                    /*  66 */
                    s11 = lea.readShort();
                    /*  67 */
                    sub = (command == 15 || command == 17) ? lea.readShort() : 0;
                    /*  68 */
                    xoffset = lea.readShort();
                    /*  69 */
                    yoffset = lea.readShort();
                    /*  70 */
                    unk161p = lea.readShort();

                    /*  72 */
                    b9 = lea.readByte();
                    /*  73 */
                    s15 = lea.readShort();
                    /*  74 */
                    b10 = lea.readByte();
                    /*  75 */
                    alm = new AbsoluteLifeMovement(command, new Point(s2, s4), s15, b9);
                    /*  76 */
                    alm.setNewFH(s11);
                    /*  77 */
                    alm.setSub(sub);
                    /*  78 */
                    alm.setunk161p(unk161p);
                    /*  79 */
                    alm.setPixelsPerSecond(new Point(s5, s7));
                    /*  80 */
                    alm.setOffset(new Point(xoffset, yoffset));
                    /*  81 */
                    alm.setEnd(b10);
                    /*  82 */
                    res.add(alm);

                    break;


                case 1:

                case 2:

                case 18:

                case 21:

                case 22:

                case 24:

                case 28:

                case 59:

                case 62:

                case 63:

                case 64:

                case 65:

                case 66:

                case 67:

                case 97:
                    /* 100 */
                    xmod = lea.readShort();
                    /* 101 */
                    ymod = lea.readShort();
                    /* 102 */
                    b1 = lea.readByte();
                    /* 103 */
                    s6 = lea.readShort();
                    /* 104 */
                    b4 = lea.readByte();
                    /* 105 */
                    rlm = new RelativeLifeMovement(command, new Point(xmod, ymod), s6, b1);
                    /* 106 */
                    rlm.setEnd(b4);
                    /* 107 */
                    res.add(rlm);

                    break;















                case 12:
                    /* 124 */
                    res.add(new ChangeEquipSpecialAwesome(command, lea.readByte()));

                    break;


                case 3:

                case 4:

                case 5:

                case 6:

                case 7:

                case 9:

                case 10:

                case 11:

                case 13:

                case 26:

                case 27:

                case 51:

                case 52:

                case 53:

                case 81:

                case 82:

                case 83:

                case 85:

                case 87:

                case 99:

                case 102:
                    /* 148 */
                    s1 = lea.readShort();
                    /* 149 */
                    s3 = lea.readShort();
                    /* 150 */
                    fh = lea.readShort();
                    /* 151 */
                    b2 = lea.readByte();
                    /* 152 */
                    s10 = lea.readShort();
                    /* 153 */
                    b7 = lea.readByte();
                    /* 154 */
                    cm = new ChairMovement(command, new Point(s1, s3), s10, b2);
                    /* 155 */
                    cm.setNewFH(fh);
                    /* 156 */
                    cm.setEnd(b7);
                    /* 157 */
                    res.add(cm);

                    break;


                case 29:

                case 30:

                case 31:

                case 32:

                case 33:

                case 34:

                case 35:

                case 36:

                case 37:

                case 38:

                case 39:

                case 40:

                case 41:

                case 42:

                case 43:

                case 44:

                case 45:

                case 46:

                case 47:

                case 49:

                case 50:

                case 54:

                case 56:

                case 57:

                case 58:

                case 60:

                case 61:

                case 75:

                case 76:

                case 77:

                case 79:

                case 84:

                case 86:

                case 88:

                case 89:

                case 90:

                case 91:

                case 93:

                case 94:

                case 95:

                case 96:
                    /* 201 */
                    newstate = lea.readByte();
                    /* 202 */
                    duration = lea.readShort();
                    /* 203 */
                    end = lea.readByte();
                    /* 204 */
                    am = new AranMovement(command, new Point(0, 0), duration, newstate);
                    /* 205 */
                    am.setEnd(end);
                    /* 206 */
                    res.add(am);

                    break;























                case 55:

                case 68:

                case 101:
                    /* 233 */
                    xpos = lea.readShort();
                    /* 234 */
                    ypos = lea.readShort();
                    /* 235 */
                    xwobble = lea.readShort();
                    /* 236 */
                    ywobble = lea.readShort();
                    /* 237 */
                    s9 = lea.readShort();
                    /* 238 */
                    b6 = lea.readByte();
                    /* 239 */
                    s14 = lea.readShort();
                    /* 240 */
                    b8 = lea.readByte();
                    /* 241 */
                    slm = new StaticLifeMovement(command, new Point(xpos, ypos), s14, b6);
                    /* 242 */
                    slm.setPixelsPerSecond(new Point(xwobble, ywobble));
                    /* 243 */
                    slm.setNewFH(s9);
                    /* 244 */
                    slm.setEnd(b8);
                    /* 245 */
                    res.add(slm);

                    break;


                case 23:
                    /* 249 */
                    xpos = lea.readShort();
                    /* 250 */
                    ypos = lea.readShort();
                    /* 251 */
                    xwobble = lea.readShort();
                    /* 252 */
                    ywobble = lea.readShort();
                    /* 253 */
                    b3 = lea.readByte();
                    /* 254 */
                    s12 = lea.readShort();
                    /* 255 */
                    lea.skip(1);
                    /* 256 */
                    um = new UnknownMovement(command, new Point(xpos, ypos), s12, b3);
                    /* 257 */
                    um.setPixelsPerSecond(new Point(xwobble, ywobble));
                    /* 258 */
                    res.add(um);

                    break;



                default:
                    /* 263 */
                    return null;

            }


        }
        /* 267 */
        double skip = lea.readByteAsInt();
        /* 268 */
        skip = Math.ceil(skip / 2.0D);
        /* 269 */
        lea.skip((int) skip);
        /* 270 */
        if (numCommands != res.size()) {
            /* 271 */
            log.warn(getKindName(kind) + " 循环次数[" + numCommands + "]和实际上获取的循环次数[" + res.size() + "]不符" + packet);
            /* 272 */
            return null;

        }
        /* 274 */
        return res;

    }


    public static void updatePosition(List<LifeMovementFragment> movement, AnimatedMapleMapObject target, int yoffset) {
        /* 277 */
        if (movement == null) {

            return;

        }
        /* 280 */
        for (LifeMovementFragment move : movement) {
            /* 281 */
            if (move instanceof LifeMovement) {
                /* 282 */
                if (move instanceof AbsoluteLifeMovement) {
                    /* 283 */
                    Point position = move.getPosition();
                    /* 284 */
                    position.y += yoffset;
                    /* 285 */
                    target.setPosition(position);

                }
                /* 287 */
                target.setStance(((LifeMovement) move).getNewstate());

            }

        }

    }




    public static String getKindName(int kind) {
        String moveMsg;
        switch (kind) {
            case 1:
                moveMsg = "玩家";
                break;
            case 2:
                moveMsg = "怪物";
                break;
            case 3:
                moveMsg = "宠物";
                break;
            case 4:
                moveMsg = "召唤兽";
                break;
            case 5:
                moveMsg = "龙龙";
                break;
            case 6:
                moveMsg = "怪怪";
                break;
            case 7:
                moveMsg = "小白";
                break;
            case 8:
                moveMsg = "小白人型";
                break;
            case 9:
                moveMsg = "安卓";
                break;
            default:
                moveMsg = "未知kind";
                break;
        }
        return moveMsg;
    }

}


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\MovementParse.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */